package com.yueka.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yueka.mapper.ActivityMapper;
import com.yueka.pojo.PageResult;
import com.yueka.pojo.activity.Activity;
import com.yueka.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;
    @Override
    public PageResult<Activity> list(String activityName, String status, String isBanner, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<Activity> list = activityMapper.list(activityName, status, isBanner);
        Page<Activity> p = (Page<Activity>) list;
        return new PageResult<>(p.getTotal(), p.getResult());
    }

    @Override
    public void delete(Integer id) {
        activityMapper.delete(id);
    }

    @Override
    public void insert(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activity.setCreateTime(LocalDateTime.now());
        activityMapper.insert(activity);
    }

    @Override
    public void update(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.update(activity);
    }

}
